package com.cp.core.controller.api;


import com.cp.base.util.JwtUtils;
import com.cp.common.result.R;
import com.cp.core.pojo.entity.Borrower;
import com.cp.core.pojo.vo.BorrowerVo;
import com.cp.core.service.BorrowerService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * <p>
 * 借款人 前端控制器
 * </p>
 *
 * @author ming
 * @since 2022-07-27
 */
@RestController
@RequestMapping("/api/core/borrower")
@Slf4j
@Api(tags = "借款人操作")
public class BorrowerController {
    @Resource
    private BorrowerService borrowerService;
    @PostMapping("/auth/save")
    public R save(@RequestBody BorrowerVo borrowerVo, HttpServletRequest request){
        String token = request.getHeader("token");
        Long userId = JwtUtils.getUserId(token);
        borrowerService.saveBorrowerVoByUserId(borrowerVo,userId);
        return R.ok().message("信息提交成功");
    }
    @ApiOperation("获取借款人认证转态")
    @GetMapping("/auth/getBorrowerStatus")
    public R getBorrowerStatus(HttpServletRequest request){
        Long userId = JwtUtils.getUserId(request.getHeader("token"));
        Integer status = borrowerService.getStatusByUserId(userId);
        return R.ok().data("borrowerStatus",status);
    }

}

